package sms.model;

import org.joda.time.DateTime;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 短信发送的错误码和错误信息定义在这里.
 * Created by zijun.song on 2015/9/21.
 */
public class Result implements Serializable {

    //短信通知返回错误码
    public  static Integer SMS_SEND_SUCCESS = 1;    //短信发送成功.
    public  static Integer SMS_SEND_FAILURE = 0;    //短信发送失败
    public  static Integer INVALID_PHONE_NUMBER = -1; //非法手机号码
    public  static Integer INCLUDE_SENSITIVE_WORD = -2; //包含敏感词
    public  static Integer SMS_GATAWAI_LIMITED = -3;  //已被加入黑名单
    public  static Integer SMS_TIMES_LIMITED = -4;  //发送短信超过最多次数.
    public  static Integer SMS_SYS_ERR = -5;        //系统异常
    public  static Integer SMS_SEND_TOO_OFTEN = -6;  //.发送太频繁,稍后再试
    public  static Integer SMS_NOT_SUPPORT_PHONES = -9999;  //.发送太频繁,稍后再试

    public  static Integer SMS_LONG_ERROR = -10;  //.消息长度错误
    public  static Integer SMS_MOBILE_COUNT_ERROR = -11;  //.请输入正确的手机号
    public  static Integer SMS_NO_TRANSMISSION_LINE = -12;  //.无发送额度
    public  static Integer SMS_ERROR_SENT_TIME = -13;  //.不在发送时间内
    public  static Integer SMS_NO_PRODUCT = -14;  //.无此产品，用户为订购
    public  static Integer SMS_ERROR_EXTNO = -15;  //.extno格式错误（非数字或长度不对）
    public  static Integer SMS_AUTO_AUDIT_BACK = -16;  //.自动审核驳回
    public  static Integer SMS_SIGN_ERROR = -17;  //.签名不合法，未带签名（用户必须带签名的前提下）
    public  static Integer SMS_IP_ERROR = -18;  //.IP地址认证错，请求的IP不是系统登记的IP地址
    public  static Integer SMS_AUTHORITY_ERROR = -19;  //.用户没有相应的发送权限
    public  static Integer SMS_OVERDUE_ERROR = -20;  //.用户已过期


    private static Map<Integer, String> resultMap = new HashMap<Integer, String>();

    static{
        resultMap.put(SMS_SEND_SUCCESS,"发送成功");
        resultMap.put(SMS_SEND_FAILURE,"发送失败");
        resultMap.put(INVALID_PHONE_NUMBER,"非法手机号码");
        resultMap.put(INCLUDE_SENSITIVE_WORD,"包含敏感词");
        resultMap.put(SMS_GATAWAI_LIMITED,"已被加入黑名单");
        resultMap.put(SMS_TIMES_LIMITED,"发送短信超过最多次数");
        resultMap.put(SMS_SYS_ERR,"系统异常");
        resultMap.put(SMS_SEND_TOO_OFTEN,"发送太频繁,稍后再试");
        resultMap.put(SMS_NOT_SUPPORT_PHONES,"暂不支持多个号码发送");

        resultMap.put(SMS_LONG_ERROR,"消息长度错误");
        resultMap.put(SMS_MOBILE_COUNT_ERROR,"请输入正确的手机号");
        resultMap.put(SMS_NO_TRANSMISSION_LINE,"无发送额度");
        resultMap.put(SMS_ERROR_SENT_TIME,"不在发送时间内");
        resultMap.put(SMS_NO_PRODUCT,"无此产品，用户为订购");
        resultMap.put(SMS_ERROR_EXTNO,"extno格式错误（非数字或长度不对）");
        resultMap.put(SMS_AUTO_AUDIT_BACK,"自动审核驳回");
        resultMap.put(SMS_SIGN_ERROR,"签名不合法，未带签名");
        resultMap.put(SMS_IP_ERROR,"IP地址认证错");
        resultMap.put(SMS_AUTHORITY_ERROR,"用户没有相应的发送权限");
        resultMap.put(SMS_OVERDUE_ERROR,"用户已过期");

    }

    private boolean status; //成功  失败.

    private int code; //状态码.

    private String msg; //消息/原因.

    private Integer id ; //短信编号.

    private String content ; //短信内容

    public Result(boolean status, int code, String msg) {
        this.status = status;
        this.code = code;
        this.msg = msg;
        if (status){
            id = DateTime.now().getMillisOfSecond();
        }
    }

    public boolean isStatus() {
        return status;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public Integer getId() {
        return id;
    }

    public static Result returnSuccess(int code){
        return new Result(true,code,resultMap.get(code));
    }

    public static Result returnFail(int code){
        return new Result(false,code,resultMap.get(code));
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}
